package com.lin.manager.controller.system;

import com.lin.manager.common.resp.R;
import com.lin.manager.system.model.vo.LogQueryParamVO;
import com.lin.manager.system.service.SysErrorLogService;
import com.lin.manager.system.service.SysLoginLogService;
import com.lin.manager.system.service.SysOperateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作者: 林江
 * @创建时间: 2024-03-19 14:51:14
 * @功能:
 */
@Api(tags = "日志管理")
@RestController
@RequestMapping("log")
public class SysLogController {

    @Autowired
    SysLoginLogService sysLoginLogService;
    @Autowired
    private SysOperateLogService sysOperateLogService;
    @Autowired
    private SysErrorLogService sysErrorLogService;

    @ApiOperation("日志管理 - 获取登录日志")
    @GetMapping("listLogLoginByPage")
    public R listLogLoginByPage(LogQueryParamVO page) {
        return R.ok(sysLoginLogService.listLogLoginByPage(page));
    }

    @ApiOperation("日志管理 - 获取操作日志")
    @GetMapping("listLogOperateByPage")
    public R listLogOperateByPage(LogQueryParamVO pageVO) {
        return R.ok(sysOperateLogService.listLogOperateByPage(pageVO));
    }

    @ApiOperation("日志管理 - 获取异常日志")
    @GetMapping("listLogErrorByPage")
    public R listLogErrorByPage(LogQueryParamVO pageVO) {
        return R.ok(sysErrorLogService.listLogErrorByPage(pageVO));
    }

    @ApiOperation("日志管理 - 删除登录日志")
    @DeleteMapping("delLogLogin")
    public R delLogLogin(Long id) {
        sysLoginLogService.delLog(id);
        return R.ok();
    }

    @ApiOperation("日志管理 - 删除操作日志")
    @DeleteMapping("delLogOperate")
    public R delLogOperate(Long id) {
        Assert.notNull(id, "id不能为空");
        sysOperateLogService.delLog(id);
        return R.ok();
    }

    @ApiOperation("日志管理 - 删除异常日志")
    @DeleteMapping("delLogError")
    public R delLogError(Long id) {
        Assert.notNull(id, "id不能为空");
        sysErrorLogService.delLog(id);
        return R.ok();
    }

//    @ApiOperation("日志管理 - 统计操作日志，按1-周，2-月，3-年")
//    @GetMapping("statistics")
//    public R statistics(Integer type) {
//        return R.ok(sysLogService.statistics(type));
//    }

}
